<?php
// Module Definition
$module['name'] = 'HD Quota';
$module['description'] = 'Checks and enforces quotas on hard disk usage.';
$module['depends'] = array('unix_users');

switch($action) {
	case 'register':
		break;
	case 'unregister':
		break;
	case 'enable':
		$SQL = 'INSERT INTO crons(month, week, day, hour, minute, user, comment, fork, timeout, hook, createdby)
			VALUES("*", "*", "*", "*", "1", "", "Run HD quota checks.", 1, 0, "server:hdquota:check", "hdquota.mod.phps")';
		$res = mysql_query($SQL);
		$SQL = 'INSERT INTO crons(month, week, day, hour, minute, user, comment, fork, timeout, hook, createdby)
			VALUES("*", "*", "*", "3", "30", "webcp", "Send HD quota warnings.", 1, 0, "server:hdquota:warn", "hdquota.mod.phps")';
		$res = mysql_query($SQL);
		$SQL = "INSERT INTO crons(month, week, day, hour, minute, user, comment, fork, timeout, php, createdby)
			VALUES ('*', '*', '1', '4', '20', '', 'Check that user quotas are accurate.', 1, 0, '$result = exec($cfg[prog][quotacheck].\" -agum\");', 'hdquota.mod.phps')";
		$res = mysql_query($SQL);
		return $res;
		break;
	case 'disable':
		$SQL = 'DELETE FROM crons WHERE createdby = "hdquota.mod.phps"';
		$res = mysql_query($SQL);
		return $res;
		break;
	case 'hook':
		register_hook('server:hdquota:check', 'hd_quota_check');
		register_hook('server:hdquota:warn', 'hd_quota_warn');
		
		global $cfg;
		switch ($cfg['os']) {
			case 'linux':
				register_hook('server:user:create', 'hd_quota_set_linux', 1);
				register_hook('server:user:update', 'hd_quota_set_linux', 1);
				break;
			case 'freebsd':
				register_hook('server:user:create', 'hd_quota_set_bsd', 1);
				register_hook('server:user:update', 'hd_quota_set_bsd', 1);
				break;
		}
		break;
}
?>